﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class SendFeedBack : System.Web.UI.Page
{
    static UserLogin user;

    protected void Page_Load(object sender, EventArgs e)
    {
        user = (UserLogin)Session["User"];

        if (user == null)
        {
            Response.Redirect("~/UserLogin.aspx");
        }

        if (!IsPostBack)
        {
            txtSubject.Text = "FeedBack to Sharemp3.com";
            lblFrom.Text = "from <b>" + user.Name + "</b>";
        }
        
        lblTime.Text = DateTime.Now.ToString();
    }

    protected void SubmitFeedBack(object sender, EventArgs e)
    {
        string content = FeedBackEditor.Content;

        if (!String.IsNullOrEmpty(content))
        {
            Sharemp3DataContext db = new Sharemp3DataContext();

            try
            {
                int userid = user.UserID;
                string subject = txtSubject.Text;
                DateTime sendDate = DateTime.Now;

                db.FeedBacks.InsertOnSubmit(new FeedBack() { UserID = userid, Subject = subject, Content = content, SendDate = sendDate });

                db.SubmitChanges();

                lblResult.Text = "Sended !";                            
            }
            catch
            {
                lblResult.Text = "Send fail !";
            }
        }
        else
        {
            lblResult.Text = "Content cannot empty !";
        }
    }
}